<template>
  <div class="home-container">
    <navbar :showHeaderIcon="true" />
    <div class="app-container">
      <div class="page-card top-tabs">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="评阅教师管理" name="pyjsgl"></el-tab-pane>
          <el-tab-pane label="考生管理" name="ksgl"></el-tab-pane>
        </el-tabs>
      </div>

      <div class="page-card m-top">
        <component
          ref="component"
          v-if="xmxx.id"
          :xmxx="xmxx"
          :xmxklb="xklb"
          :is="activeTab"
        ></component>
      </div>
    </div>
  </div>
</template>

<script>
import { Navbar } from "@/layout/components";
import pyjsgl from "./pyjsgl";
import ksgl from "./ksgl";
import { subjectlistselect } from "@/api/common";
import { grouplist } from "@/api/jcgl/xkgl";
export default {
  components: {
    Navbar,
    pyjsgl,
    ksgl,
  },
  data() {
    return {
      xmxx: {},

      activeTab: this.$route.query.activeTab,

      qbxklb: [],
      xklxlb: [],
    };
  },
  computed: {
    xklb() {
      let xklb = [];
      if (this.xmxx.selectType && this.xklxlb.length > 0) {
        let obj = this.xklxlb.filter((item) => {
          return this.xmxx.selectType == item.id;
        })[0];
        let examSubjects = obj.examSubjects.split(",");
        let basicChooseSubject;
        if (obj.basicChooseSubject) {
          basicChooseSubject = obj.basicChooseSubject.map((item) => {
            return item.selectSubjectIds.split(",");
          });
          basicChooseSubject = basicChooseSubject.reduce((acc, curr) => {
            return acc.concat(curr);
          }, []);
          examSubjects = examSubjects.concat(basicChooseSubject);
        }

        this.qbxklb.map((item) => {
          if (examSubjects.indexOf(item.subjectId.toString()) != -1) {
            xklb.push(item);
          }
        });
      }

      return xklb;
    },
  },
  created() {
    this.$store.dispatch("getXmxx").then((res) => {
      this.xmxx = res;
    });
    grouplist({ pageNum: 1, pageSize: 9999 }).then((res) => {
      this.xklxlb = res.rows;
    });
    subjectlistselect("-1").then((res) => {
      this.qbxklb = res.data;
    });
  },
};
</script>

<style scope>
</style>